package com.example.springcloudorderserver1030;

import com.example.springcloudorderserver1030.annotation.NoScan;
import com.example.springcloudorderserver1030.config.RibbonConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.client.RestTemplate;

/**
 * 订单的启动类
 * 还可以通过@RibbonClients对多个服务进行策略配置
 * @RibbonClients({
 *      @RibbonClient(value = "服务名",configuration = RibbonConfig.class),
 *      @RibbonClient(value = "服务名",configuration = RibbonConfig.class)
 * })
 *
 * @EnableEurekaClient： 标记该应用是 Eureka客户端
 */
@EnableEurekaClient
@SpringBootApplication
//排除NoScan标签所在的类
@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION,value= NoScan.class))
@RibbonClient(value="user-server",configuration=RibbonConfig.class)
@EnableCircuitBreaker   //开启Hystrix熔断
public class SpringcloudOrderServer1030Application {

    //配置一个RestTemplate ，Spring封装的一个基于Restful风格的http客户端 工具
    @Bean
    @LoadBalanced  //加上负载均衡的注解，让RestTemplate具有负载均衡的能力
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

  /*  @Bean
    //配置负载均衡算法为随机算法（性能最好）
    public RandomRule randomRule(){return new RandomRule();}*/

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudOrderServer1030Application.class, args);
    }

}
